<?php

namespace App\Controller;
use App\Library\System\Model\AliasModel;

/**
 * Alias Controller
 *
 * @category   App
 * @package    App\Controller
 * @author     Loi Nguyen <loint@peslook.com>
 * @copyright  Penlook
 * @version    1.0
 * @since      Class available since Release 1.0
 */
class AliasController extends BaseController
{
    /**
     * Index
     *
     * @router /alias
     * @return array|void
     */
    public function indexAction()
    {
        $alias = $this->route('alias');
        $model = new AliasModel($alias);

        if (!$model->isValid()) {
            return $this->error(404);
        }

        $controller_class = __NAMESPACE__.'\\'.$model->getController();

        if (!$controller_class) {
            return $this->error(404);
        }

        return $this->forward()->dispatch($controller_class, array(
            'action' => 'index',
            'id' => $model->pid
        ));
    }
}